package com.neusoft.actor.controller;

import com.neusoft.actor.po.Client;
import com.neusoft.actor.po.ResponseBean;
import com.neusoft.actor.service.ClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
//@CrossOrigin("*")
@RequestMapping("/ClientController")
public class ClientController {

    @Autowired
    private ClientService clientService;

    @GetMapping("/queryAll")
//    查询所有老人，默认自理
    public ResponseBean<List<Client>> getAllClients() {
        return clientService.getAllClients();
    }


    @GetMapping("/getClientsWithoutCaretaker")
//   询没有管家的客户,可以根据客户名条件查询
    public ResponseBean<List<Client>> getClientsWithoutCaretaker(@RequestParam(required = false) String clientName) {
        return clientService.getClientsWithoutCaretaker(clientName);
    }

    @GetMapping("/getClientsByCaretaker")
//   查询某个健康管家服务的客户，根据客户名进行模糊查询
    public ResponseBean<List<Client>> getClientsByCaretaker(@RequestParam Integer caretakerId, @RequestParam(required = false) String clientName) {
        return clientService.getClientsByCaretaker(caretakerId, clientName);
    }


    @GetMapping("/queryByCon")
//        条件查询
    public ResponseBean<List<Client>> getClientsByCondition(
            @RequestParam(required = false) String clientName,
            @RequestParam(required = false) String isSelfCare) {
        return clientService.getClientsByCondition(clientName, isSelfCare);
    }

    @PostMapping("/addClient")
//    登记入住信息
    public ResponseBean<Integer> addClient(@RequestBody Client client) {
        return clientService.addClient(client);
    }

    @PutMapping("/updateClient")
    public ResponseBean<Integer> updateClient(@RequestBody Client client) {
        client.setClientId(client.getClientId());
        return clientService.updateClient(client);
    }

    @DeleteMapping("/deleteClient")
//    逻辑删除
    public ResponseBean<Integer> deleteClient(@RequestParam Integer id) {
        Client client = clientService.getClientById(id).getData();
        if (client != null) {
            client.setActive(false);
        }
        return clientService.updateClient(client);
    }

    @GetMapping("/getClientById")
//    按客户id查询客户
    public ResponseBean<Client> getClientById(Integer clientId) {
        return clientService.getClientById(clientId);
    }
}